package com.qtenv.datasync.utils;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;

import java.util.List;
import java.util.Map;

/**
 * @ClassName CustomUtil
 * @Author CBL
 * @Date 2022/8/4 18:45
 **/
public class CustomUtil {
    public static <T> List<Map<String, Object>> transformZbxToTextValueList(T t, String[] keyArr, String[] valueArr) {
        List<Map<String, Object>> result = CollectionUtil.newArrayList();

        if (t != null) {
            for (int i = 0; i < keyArr.length; i++) {
                Map<String, Object> tmpMap = MapUtil.newHashMap();

                tmpMap.put("text", keyArr[i]);
                tmpMap.put("value", BeanUtil.getFieldValue(t, valueArr[i]));

                result.add(tmpMap);
            }
        }

        return result;
    }
}
